from app.extensions import db
from app.modules.common.utils import JsonEncoder


class Agent(db.Model, JsonEncoder):
    __tablename__ = "agent"
    id = db.Column(db.String, primary_key = True)
    ip = db.Column(db.String)
    load_level = db.Column(db.Integer, nullable = False)
    machine_ip = db.Column(db.String, nullable = False)
    level_name = db.Column(db.String)
    vm_id = db.Column(db.String)
    is_del = db.Column(db.String)

    def __init__(self, id, ip, load_level, machine_ip, level_name, vm_id = None, is_del = '1'):
        self.id = id
        self.ip = ip
        self.load_level = load_level
        self.machine_ip = machine_ip
        self.level_name = level_name
        self.vm_id = vm_id
        self.is_del = is_del

    def to_dict(self):
        return {
            'id': self.id,
            'ip': self.ip,
            'load_level': self.load_level,
            'machine_ip': self.machine_ip,
            'level_name': self.level_name,
            'vm_id': self.vm_id,
            'is_del': self.is_del,
        }
